package at.fpmedv.eclipse.helma.core;

import helma.framework.core.PrototypeDecorator;
import helma.framework.repository.Resource;

import java.util.ArrayList;
import java.util.Comparator;

import at.fpmedv.eclipse.helma.util.ResourceContainer;

public class SkinGroupTreeObject implements ITreeParent {
	
	private ITreeParent parent;
	private PrototypeDecorator proto;

	public SkinGroupTreeObject(PrototypeDecorator proto,ITreeParent parent) {
		this.parent = parent;
		this.proto = proto;
	}
	
	public ITreeObject[] getChildren() {
		ArrayList<ITreeObject> result = new ArrayList<ITreeObject>();
		result.addAll(proto.getSkins(this));
		return (ITreeObject[]) result.toArray(new ITreeObject[result.size()]);
	}

	public ArrayList<Resource> getResources() {
		return parent.getResources();
	}

	public boolean hasChildren() {
		return getChildren().length > 0;
	}

	public int compare(ITreeObject element, Comparator comparator) {
		if (element instanceof FunctionTreeObject)
			return -1;
		// smaller than everything else
		return 1;
	}

	public Object getAdapter(Class key) {
		return null;
	}

	public String getName() {
		return "Skins";
	}

	public ITreeParent getParent() {
		return parent;
	}

	public String getRawName() {
		return getName();
	}

	public ResourceContainer getResource() {
		return parent.getResource();
	}
	
	public String toString() {
		return getName();
	}

}
